package cn.tedu.mall.front.controller;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.front.service.IFrontProductService;
import cn.tedu.mall.pojo.product.vo.AttributeStandardVO;
import cn.tedu.mall.pojo.product.vo.SpuListItemVO;
import cn.tedu.mall.pojo.product.vo.SpuStandardVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/front/spu")
@Api(tags = "前台商品spu模块")
public class    FrontSpuController {

    @Autowired
    private IFrontProductService frontProductService;

    // localhost:10004/front/spu/list/3
    @ApiOperation("根据分类id分页查询Spu列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId",value = "分类id",example = "3"),
            @ApiImplicitParam(name = "page",value = "页码",example = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页条数",example = "2")
    })
    @GetMapping("/list/{categoryId}")
    public JsonResult<JsonPage<SpuListItemVO>> listSpuByPage(@PathVariable Long categoryId,Integer page,Integer pageSize){
        JsonPage<SpuListItemVO> jsonPage = frontProductService.listSpuByCategoryId(categoryId, page, pageSize);
        return JsonResult.ok(jsonPage);
    }

    // 根据spuId查询spu信息
    @ApiOperation("根据spuId查询spu信息")
    @ApiImplicitParam(name = "spuId",value = "spuId",example = "1")
    @GetMapping("/{spuId}")
    public JsonResult<SpuStandardVO> getFrontSpuById(@PathVariable Long spuId){
        SpuStandardVO spuStandardVO = frontProductService.getFrontSpuById(spuId);
        return JsonResult.ok(spuStandardVO);
    }

    // 根据spuId查询所有属性\规格
    @ApiOperation("根据spuId查询所有属性/规格")
    @ApiImplicitParam(name = "spuId",value = "spuId",example = "1")
    @GetMapping("/template/{spuId}")
    public JsonResult<List<AttributeStandardVO>> getAttributesBySpuId(@PathVariable Long spuId){
        List<AttributeStandardVO> attributeList = frontProductService.getSpuAttributesBySpuId(spuId);
        return JsonResult.ok(attributeList);
    }
}
